﻿package mortal.game.view.copy.escort
{
    import Message.Public.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import flash.geom.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.ai.*;
    import mortal.game.scene3D.layer3D.utils.*;
    import mortal.game.scene3D.map3D.util.*;
    import mortal.game.scene3D.player.entity.*;
    import mortal.game.scene3D.player.info.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.*;
    import mortal.game.view.copy.QuestionCopy.data.*;
    import mortal.game.view.guildNew.*;
    import mortal.game.view.task.data.*;
    import mortal.mvc.core.*;

    public class EscortRightInfoWin extends CopyInfoPanelBase
    {
        private var _bgImg:GImageBitmap;
        private var _escortName:GTextFiled;
        private var _escortState:GTextFiled;
        private var _rentBtn:GLoadingButton;
        private var _keepEscort:GLoadingButton;
        private var _searchEscort:GLoadingButton;
        private static var _instance:EscortRightInfoWin;

        public function EscortRightInfoWin(param1:String = "", param2:int = 250, param3:int = 380, param4:int = 6)
        {
            super(ImagesConst.copyInfoPanelTitle_escort, 262, 251, 10);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            Dispatcher.dispatchEvent(new DataEvent(EventName.Wing288IconShowHide, false));
            this._bgImg = UIFactory.gImageBitmap(ImagesConst.EscortRightInfoBg, 0, 0, _bodySprite);
            var _loc_1:* = GlobalStyle.textFormatHuang2;
            this._escortName = UIFactory.gTextField("", 120, 60, 100, 20, _bodySprite, _loc_1);
            this._escortState = UIFactory.gTextField("", 120, 95, 100, 20, _bodySprite, _loc_1);
            this._rentBtn = UIFactory.gLoadingButton(ImagesConst.GuildNewMercenaryRentBtn_upSkin, 120, 120, 90, 45, _bodySprite);
            this._rentBtn.label = "";
            this._rentBtn.configEventListener(MouseEvent.CLICK, this.onRentCk);
            this._keepEscort = UIFactory.gLoadingButton(ResFileConst.JxhsBtn, 20, 180, 103, 37, _bodySprite);
            this._keepEscort.configEventListener(MouseEvent.CLICK, this.clickHandler);
            this._searchEscort = UIFactory.gLoadingButton(ResFileConst.XhbcBtn, 140, 180, 103, 37, _bodySprite);
            this._searchEscort.configEventListener(MouseEvent.CLICK, this.clickHandler);
            Cache.instance.role.roleEntityInfo.addEventListener(EntityInfoEventName.UpdateLevel, this.updateBtnEnable);
            this.updateBtnEnable();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.Wing288IconShowHide, true));
            Cache.instance.role.roleEntityInfo.removeEventListener(EntityInfoEventName.UpdateLevel, this.updateBtnEnable);
            this._bgImg.dispose(param1);
            this._bgImg = null;
            this._escortState.dispose(param1);
            this._escortState = null;
            this._rentBtn.dispose(param1);
            this._rentBtn = null;
            this._escortName.dispose(param1);
            this._escortName = null;
            this._keepEscort.dispose(param1);
            this._keepEscort = null;
            this._searchEscort.dispose(param1);
            this._searchEscort = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function updateBtnEnable(event:Event = null) : void
        {
            var _loc_2:* = Cache.instance.role.entityInfo.level;
            this._rentBtn.filterEnabled = LevelCheckUtil.isLevelEnougth(LevelCheckUtil.mercenary);
            return;
        }// end function

        private function onRentCk(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildOpen, GuildNewModule.Mercenary));
            return;
        }// end function

        private function clickHandler(event:MouseEvent) : void
        {
            var _loc_2:IEntity = null;
            if (event.target == this._searchEscort)
            {
                _loc_2 = ThingUtil.entityUtil.getSelfEscortEntity();
                if (_loc_2)
                {
                    AIManager.cancelAll();
                    AIManager.addMoveToOtherMap(MapFileUtil.mapID, MapFileUtil.mapID, new Point(_loc_2.x2d, _loc_2.y2d), 0);
                    AIManager.start();
                }
                else
                {
                    GameProxy.task.getEscortInfoPos();
                }
            }
            else if (event.target == this._keepEscort)
            {
                if (CopyUtil.isHasNomalEscortTask)
                {
                    TaskUtil.linkTask(Cache.instance.task.getTaskInfoByGroup(ETaskGroup._ETaskGroupEscort));
                }
            }
            return;
        }// end function

        private function getEscortNameByIndex(param1:int, param2:String) : String
        {
            var _loc_3:String = null;
            var _loc_4:String = null;
            switch(param1)
            {
                case EColor._EColorWhite:
                {
                    _loc_4 = Language.getString(35202);
                    break;
                }
                case EColor._EColorGreen:
                {
                    _loc_4 = Language.getString(35203);
                    break;
                }
                case EColor._EColorBlue:
                {
                    _loc_4 = Language.getString(35204);
                    break;
                }
                case EColor._EColorPurple:
                {
                    _loc_4 = Language.getString(35205);
                    break;
                }
                case EColor._EColorOrange:
                {
                    _loc_4 = Language.getString(35206);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return "<font color=\'" + _loc_4 + Language.getString(35207) + "</font>";
        }// end function

        public function updateEscortName(param1:String) : void
        {
            var _loc_2:TaskInfo = null;
            if (CopyUtil.isHasNomalEscortTask)
            {
                _loc_2 = Cache.instance.task.getTaskInfoByGroup(ETaskGroup._ETaskGroupEscort);
                if (_loc_2)
                {
                    this._escortName.htmlText = this.getEscortNameByIndex(_loc_2.playerTask.extend, param1);
                }
            }
            return;
        }// end function

        public function updateState(param1:int) : void
        {
            if (param1 == 0)
            {
                this._escortState.htmlText = Language.getString(35208);
            }
            else
            {
                this._escortState.htmlText = Language.getString(35209);
            }
            return;
        }// end function

        public static function get instance() : EscortRightInfoWin
        {
            if (_instance == null)
            {
                _instance = new EscortRightInfoWin;
            }
            return _instance;
        }// end function

        public static function get isViewShow() : Boolean
        {
            return _instance && !_instance.isHide;
        }// end function

    }
}
